package com.cat.greedyAlgorithm;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/destroying-asteroids/description/
 * @create 2025/8/21 14:57
 * @since JDK17
 */

public class Solution05 {
    public boolean asteroidsDestroyed(int m, int[] asteroids) {
        Arrays.sort(asteroids);
        long mass = m;
        int n = asteroids.length;
        for (int i = 0; i < n; i++) {
            if (mass < asteroids[i]) {
                return false;
            }
            mass += asteroids[i];
            if (mass >= asteroids[n - 1]) {
                return true;
            }
        }
        return true;
    }
}
